Kinetis SDK API Reference Manual  1.0.0-beta
Freescale Semiconductor, Inc.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Groups Pages

The section describes the programming interface of the ADC HAL driver. More...

Enumerations

enum  adc_clock_source_mode_t {
  kAdcClockSourceBusClk = 0U,
  kAdcClockSourceBusClk2 = 1U,
  kAdcClockSourceAlternate = 2U,
  kAdcClockSourceAsynchrounous = 3U
}
 Defines the selection of the clock source that ADC module uses. More...
 
enum  adc_clock_divider_mode_t {
  kAdcClockDivider1 = 0U,
  kAdcClockDivider2 = 1U,
  kAdcClockDivider4 = 2U,
  kAdcClockDivider8 = 3U
}
 Defines the selection of the clock divider. More...
 
enum  adc_reference_voltage_mode_t {
  kAdcVoltageVref = 0U,
  kAdcVoltageValt = 1U
}
 Defines the selection of the voltage source that ADC module uses. More...
 
enum  adc_long_sample_mode_t {
  kAdcLongSampleExtra20 = 0U,
  kAdcLongSampleExtra12 = 1U,
  kAdcLongSampleExtra6 = 2U,
  kAdcLongSampleExtra2 = 3U
}
 Defines the selection of the long sample extra cycle configuration. More...
 
enum  adc_resolution_mode_t {
  kAdcSingleDiff8or9 = 0U,
  kAdcSingleDiff12or13 = 1U,
  kAdcSingleDiff10or11 = 2U,
  kAdcSingleDiff16 = 3U
}
 Defines the selection of the sample resolution. More...
 
enum  adc_group_mux_mode_t {
  kAdcChannelMuxA = 0U,
  kAdcChannelMuxB = 1U
}
 Defines the selection of the A/B group mux. More...
 
enum  adc_hw_average_mode_t {
  kAdcHwAverageCount4 = 0U,
  kAdcHwAverageCount8 = 1U,
  kAdcHwAverageCount16 = 2U,
  kAdcHwAverageCount32 = 3U
}
 Defines the selection of the time in a hard average mode. More...
 
enum  adc_channel_mode_t {
  kAdcChannel0 = 0U,
  kAdcChannell = 1U,
  kAdcChannel2 = 2U,
  kAdcChannel3 = 3U,
  kAdcChannel4 = 4U,
  kAdcChannel5 = 5U,
  kAdcChannel6 = 6U,
  kAdcChannel7 = 7U,
  kAdcChannel8 = 8U,
  kAdcChannel9 = 9U,
  kAdcChannel10 = 10U,
  kAdcChannel11 = 11U,
  kAdcChannel12 = 12U,
  kAdcChannel13 = 13U,
  kAdcChannel14 = 14U,
  kAdcChannel15 = 15U,
  kAdcChannel16 = 16U,
  kAdcChannel17 = 17U,
  kAdcChannel18 = 18U,
  kAdcChannel19 = 19U,
  kAdcChannel20 = 20U,
  kAdcChannel21 = 21U,
  kAdcChannel22 = 22U,
  kAdcChannel23 = 23U,
  kAdcChannelTemperature = 26U,
  kAdcChannelBandgap = 27U,
  kAdcChannelReferenceVoltageHigh = 29U,
  kAdcChannelReferenceVoltageLow = 30U,
  kAdcChannelDisable = 31U
}
 Defines the selection of the channel inside the ADC module. More...
 
enum  adc_status_t {
  kStatus_ADC_Success = 0U,
  kStatus_ADC_InvalidArgument = 1U,
  kStatus_ADC_Failed = 2U
}
 Defines the status returned from the ADC API. More...
 

Functions

adc_status_t adc_hal_start_calibration (uint32_t instance)
 Starts the calibration process. More...
 
static void adc_hal_end_calibration (uint32_t instance)
 Ends the calibration process. More...
 
uint32_t adc_hal_get_calibration_PG (uint32_t instance)
 Gets and calculates the plus-side calibration parameter. More...
 
static void adc_hal_set_calibration_PG (uint32_t instance, uint32_t val)
 Sets the plus-side calibration parameter to the ADC instance. More...
 
uint32_t adc_hal_get_calibration_MG (uint32_t instance)
 Gets and calculates the minus-side calibration parameter. More...
 
static void adc_hal_set_calibration_MG (uint32_t instance, uint32_t val)
 Sets the minus-side calibration parameter to the ADC instance. More...
 
static uint32_t adc_hal_get_calibration_offset (uint32_t instance)
 Gets the offset value after the auto-calibration. More...
 
static void adc_hal_set_calibration_offset (uint32_t instance, uint32_t value)
 Sets the offset value for manual calibration. More...
 
static void adc_hal_set_clock_source_mode (uint32_t instance, adc_clock_source_mode_t mode)
 Sets the selection of the clock source. More...
 
static void adc_hal_configure_asynchronous_clock (uint32_t instance, bool isEnabled)
 Switches the asynchronous clock on/off. More...
 
static void adc_hal_set_clock_divider_mode (uint32_t instance, adc_clock_divider_mode_t mode)
 Sets the selection of the clock divider. More...
 
static void adc_hal_set_reference_voltage_mode (uint32_t instance, adc_reference_voltage_mode_t mode)
 Sets the selection of the reference voltage source. More...
 
static void adc_hal_configure_high_speed (uint32_t instance, bool isEnabled)
 Switches the high speed mode on/off . More...
 
static void adc_hal_configure_long_sample (uint32_t instance, bool isEnabled)
 Switch the long sample mode on/off. More...
 
static void adc_hal_set_long_sample_mode (uint32_t instance, adc_long_sample_mode_t mode)
 Sets the selection of the long sample mode. More...
 
static void adc_hal_configure_low_power (uint32_t instance, bool isEnabled)
 Switches the low power mode on/off. More...
 
static void adc_hal_set_resolution_mode (uint32_t instance, adc_resolution_mode_t mode)
 Sets the selection of the resolution mode. More...
 
static void adc_hal_configure_continuous_conversion (uint32_t instance, bool isEnabled)
 Switches the continuous conversion mode on/off. More...
 
static void adc_hal_configure_hw_trigger (uint32_t instance, bool isEnabled)
 Switches the hardware trigger mode on/off . More...
 
static void adc_hal_configure_hw_average (uint32_t instance, bool isEnabled)
 Switches the hardware average mode on/off. More...
 
static void adc_hal_set_hw_average_mode (uint32_t instance, adc_hw_average_mode_t mode)
 Sets the selection of the hardware average mode. More...
 
static void adc_hal_configure_hw_compare (uint32_t instance, bool isEnabled)
 Switches the hardware compare mode on/off. More...
 
static void adc_hal_configure_hw_compare_greater (uint32_t instance, bool isEnabled)
 Switches the hardware compare greater configuration on/off . More...
 
static void adc_hal_configure_hw_compare_in_range (uint32_t instance, bool isEnabled)
 Switches the hardware compare range configuration on/off . More...
 
static void adc_hal_set_hw_compare_value1 (uint32_t instance, uint32_t value)
 Sets the value1 in the hardware compare. More...
 
static void adc_hal_set_hw_compare_value2 (uint32_t instance, uint32_t value)
 Sets the value2 in the hardware compare. More...
 
static void adc_hal_configure_dma (uint32_t instance, bool isEnabled)
 Switches the ADC DMA trigger on/off. More...
 
static void adc_hal_disable (uint32_t instance, uint32_t group)
 Switches off the ADC channel conversion. More...
 
static void adc_hal_enable (uint32_t instance, uint32_t group, adc_channel_mode_t mode, bool isDifferential)
 Sets the channel number and switches on the conversion. More...
 
static void adc_hal_configure_interrupt (uint32_t instance, uint32_t group, bool isEnabled)
 Switches the ADC interrupt trigger on/off . More...
 
static bool adc_hal_is_in_process (uint32_t instance)
 Checks whether the ADC is in process. More...
 
static bool adc_hal_is_conversion_completed (uint32_t instance, uint32_t group)
 Checks whether the channel conversion is complete. More...
 
static bool adc_hal_is_calibration_fail (uint32_t instance)
 Checks whether the calibration failed. More...
 
static uint32_t adc_hal_get_conversion_value (uint32_t instance, uint32_t group)
 Gets the conversion value. More...
 
static void adc_hal_set_group_mux (uint32_t instance, adc_group_mux_mode_t group)
 Sets the current group mux that executes the conversion. More...
 

ADC hal driver

Overview

The ADC HAL driver is used to mask the hardware and provide user a comprehensible way to use ADC hardware.

Enumeration Type Documentation

Enumerator
kAdcClockSourceBusClk 

Use bus clock.

kAdcClockSourceBusClk2 

Use bus clock / 2.

kAdcClockSourceAlternate 

Use the optional external clock.

kAdcClockSourceAsynchrounous 

Use ADC's internal asynchronous clock.

Enumerator
kAdcClockDivider1 

Divide 1.

kAdcClockDivider2 

Divide 2.

kAdcClockDivider4 

Divide 4.

kAdcClockDivider8 

Divide 8.

Enumerator
kAdcVoltageVref 

Use V_REFH & V_REFL as ref source pin.

kAdcVoltageValt 

Use V_ALTH & V_REFL as ref source pin.

Enumerator
kAdcLongSampleExtra20 

Extra 20 cycles, total 24 cycles, default.

kAdcLongSampleExtra12 

Extra 12 cycles.

kAdcLongSampleExtra6 

Extra 6 cycles.

kAdcLongSampleExtra2 

Extra 2 cycles.

Enumerator
kAdcSingleDiff8or9 

8-bits in single-end or 9-bits in differential.

kAdcSingleDiff12or13 

12-bits in single-end or 13-bits in differential.

kAdcSingleDiff10or11 

10-bits in single-end or 11-bits in differential.

kAdcSingleDiff16 

16-bits both in single-end and differential.

Enumerator
kAdcChannelMuxA 

Mux A group is active.

kAdcChannelMuxB 

Mux B group is active.

Enumerator
kAdcHwAverageCount4 

Average the result after accumulating 4 conversion.

kAdcHwAverageCount8 

Average the result after accumulating 8 conversion.

kAdcHwAverageCount16 

Average the result after accumulating 16 conversion.

kAdcHwAverageCount32 

Average the result after accumulating 32 conversion.

Enumerator
kAdcChannel0 

ADC channel 0.

kAdcChannell 

ADC channel 1.

kAdcChannel2 

ADC channel 2.

kAdcChannel3 

ADC channel 3.

kAdcChannel4 

ADC channel 4.

kAdcChannel5 

ADC channel 5.

kAdcChannel6 

ADC channel 6.

kAdcChannel7 

ADC channel 7.

kAdcChannel8 

ADC channel 8.

kAdcChannel9 

ADC channel 9.

kAdcChannel10 

ADC channel 10.

kAdcChannel11 

ADC channel 11.

kAdcChannel12 

ADC channel 12.

kAdcChannel13 

ADC channel 13.

kAdcChannel14 

ADC channel 14.

kAdcChannel15 

ADC channel 15.

kAdcChannel16 

ADC channel 16.

kAdcChannel17 

ADC channel 17.

kAdcChannel18 

ADC channel 18.

kAdcChannel19 

ADC channel 19.

kAdcChannel20 

ADC channel 20.

kAdcChannel21 

ADC channel 21.

kAdcChannel22 

ADC channel 22.

kAdcChannel23 

ADC channel 23.

kAdcChannelTemperature 

Internal temperature sensor.

kAdcChannelBandgap 

Internal band gap.

kAdcChannelReferenceVoltageHigh 

Internal ref voltage High.

kAdcChannelReferenceVoltageLow 

Internal ref voltage L.

kAdcChannelDisable 

Disable the sample process.

Enumerator
kStatus_ADC_InvalidArgument 

Parameter is not available for the current configuration.

kStatus_ADC_Failed 

Function operation failed.

Function Documentation

adc_status_t adc_hal_start_calibration ( uint32_t  instance)

This function clears the calibration flag bit and sets the enable bit to start the calibration.

Parameters
instanceADC instance ID.
static void adc_hal_end_calibration ( uint32_t  instance)
inlinestatic

This function clears the calibration enable bit to end the calibration.

Parameters
instanceADC instance ID.
uint32_t adc_hal_get_calibration_PG ( uint32_t  instance)

This function gets the CLP0 - CLP4 and CLPS, accumulates them, and returns the value that can be set to the PG directly.

Parameters
instanceADC instance ID.
Returns
the value that can be set to PG directly.
static void adc_hal_set_calibration_PG ( uint32_t  instance,
uint32_t  val 
)
inlinestatic

This function sets the PG register directly.

Parameters
instanceADC instance ID.
valthe value that can be set to PG directly.
uint32_t adc_hal_get_calibration_MG ( uint32_t  instance)

This function gets the CLM0 - CLM4 and CLMS, accumulates them, and returns the value that can be set to the MG directly.

Parameters
instanceADC instance ID.
Returns
the value that can be set to MG directly.
static void adc_hal_set_calibration_MG ( uint32_t  instance,
uint32_t  val 
)
inlinestatic

This function sets the MG register directly.

Parameters
instanceADC instance ID.
valthe value that can be set to MG directly.
static uint32_t adc_hal_get_calibration_offset ( uint32_t  instance)
inlinestatic

If the user wants to adjust the offset value according to the application, the origin offset value will be a reference.

Parameters
instanceADC instance ID.
Returns
The offset value created by auto-calibration.
static void adc_hal_set_calibration_offset ( uint32_t  instance,
uint32_t  value 
)
inlinestatic

This function is to set the user selected or calibration generated offset error correction value. The value set here is subtracted from the conversion and the result is transferred into the result registers (Rn). If the result is above the maximum or below the minimum result value, it is forced to the appropriate limit for the current mode of operation.

Parameters
instanceADC instance ID.
valueThe manual offset value.
static void adc_hal_set_clock_source_mode ( uint32_t  instance,
adc_clock_source_mode_t  mode 
)
inlinestatic

The selection of ADC clock source can see to the type definition of adc_clock_source_mode_t. This function selects the input clock source to generate the internal clock, ADCK. Note that when the ADACK clock source is selected, it does not have to be activated prior to the start of the conversion. When it is selected and it is not activated prior to start a conversion , the asynchronous clock will be activated at the start of a conversion and shuts off when conversions are terminated. In this case, there is an associated clock startup delay each time the clock source is re-activated.

Parameters
instanceADC instance ID.
modeThe indicated clock source mode.
static void adc_hal_configure_asynchronous_clock ( uint32_t  instance,
bool  isEnabled 
)
inlinestatic

When enables the ADC's asynchronous clock source and the clock source output regardless of the conversion and input clock select status of the ADC. Based on MCU configuration, the asynchronous clock may be used by other modules. Setting this mode allows the clock to be used even while the ADC is idle or operating from a different clock source. Also, latency of initiating a single or first-continuous conversion with the asynchronous clock selected is reduced since the ADACK clock is already operational.

Parameters
instanceADC instance ID.
isEnabledThe switcher.
static void adc_hal_set_clock_divider_mode ( uint32_t  instance,
adc_clock_divider_mode_t  mode 
)
inlinestatic

The selection of ADC's clock divider can see to the type definition of the adc_clock_divider_mode_t. This function selects the divide ratio used by the ADC to generate the internal clock ADCK.

Parameters
instanceADC instance ID.
modeThe selection of the divider.
static void adc_hal_set_reference_voltage_mode ( uint32_t  instance,
adc_reference_voltage_mode_t  mode 
)
inlinestatic

The selection of ADC's reference voltage can see to the type definition of adc_reference_voltage_mode_t. This function selects the voltage reference source used for conversions.

Parameters
instanceADC instance ID.
modeThe selection of the reference voltage source.
static void adc_hal_configure_high_speed ( uint32_t  instance,
bool  isEnabled 
)
inlinestatic

This function configures the ADC for high speed operations. The conversion sequence is altered (2 ADCK cycles added to the conversion time) to allow higher speed conversion clocks.

Parameters
instanceADC instance ID.
isEnabledThe switcher.
static void adc_hal_configure_long_sample ( uint32_t  instance,
bool  isEnabled 
)
inlinestatic

This function selects between the different sample times based on the conversion mode selected. It adjusts the sample period to allow higher impedance inputs to be accurately sampled or to maximize conversion speed for lower impedance inputs. Longer sample times can also be used to lower overall power consumption if the continuous conversions are enabled and the high conversion rates are not required. In fact this will be able to charge the SAR in a timely manner way without affecting the SAR configuration.

Parameters
instanceADC instance ID.
isEnabledThe switcher.
static void adc_hal_set_long_sample_mode ( uint32_t  instance,
adc_long_sample_mode_t  mode 
)
inlinestatic

The selection of ADC long sample mode can see to the type definition of the adc_long_sample_mode_t. This function selects the long sample mode that indicating the different count of extra ADCK cycles are needed.

Parameters
instanceADC instance ID.
modeThe selection of long sample mode.
static void adc_hal_configure_low_power ( uint32_t  instance,
bool  isEnabled 
)
inlinestatic

This function controls the power configuration of the successive approximation converter. This optimizes power consumption when higher sample rates are not required.

Parameters
instanceADC instance ID.
isEnabledThe switcher.
static void adc_hal_set_resolution_mode ( uint32_t  instance,
adc_resolution_mode_t  mode 
)
inlinestatic

The selection of ADC resolution mode can see to the type definition of the adc_resolution_mode_t. This function selects the ADC resolution mode. Note that the differential conversion is different to single-end conversion.

Parameters
instanceADC instance ID.
modeThe selection of resolution mode.
static void adc_hal_configure_continuous_conversion ( uint32_t  instance,
bool  isEnabled 
)
inlinestatic

This function configures the continuous conversions or sets of conversions if the hardware average function is enabled after initiating a conversion.

Parameters
instanceADC instance ID.
isEnabledThe switcher.
static void adc_hal_configure_hw_trigger ( uint32_t  instance,
bool  isEnabled 
)
inlinestatic

This function selects the type of trigger used for initiating a conversion. Two types of triggers can be selected: software trigger and hardware trigger. When software trigger is selected, a conversion is initiated following a write to SC1A. When hardware trigger is selected, a conversion is initiated following the assertion of the external events. The event will come through the signal on the line of ADHWT input after a pulse of ADHWTSn input inside SOC.

Parameters
instanceADC instance ID.
isEnabledThe switcher.
static void adc_hal_configure_hw_average ( uint32_t  instance,
bool  isEnabled 
)
inlinestatic

This function enables the hardware average function of the ADC.

Parameters
instanceADC instance ID.
isEnabledThe switcher.
static void adc_hal_set_hw_average_mode ( uint32_t  instance,
adc_hw_average_mode_t  mode 
)
inlinestatic

The selection of ADC hardware average mode can see to the type definition of the adc_hw_average_mode_t. This function determines how many ADC conversions are averaged to create the ADC average result.

Parameters
instanceADC instance ID.
modeThe selection of hardware average mode.
static void adc_hal_configure_hw_compare ( uint32_t  instance,
bool  isEnabled 
)
inlinestatic

This function enables the compare function.

Parameters
instanceADC instance ID.
isEnabledThe switcher.
static void adc_hal_configure_hw_compare_greater ( uint32_t  instance,
bool  isEnabled 
)
inlinestatic

This function configures the compare function to check the conversion result relative to the compare value register(s) (CV1 and CV2). To enable will configure greater than or equal to threshold, outside range inclusive and inside range inclusive functionality based on the values placed in the CV1 and CV2 registers. Otherwise, it will configure less than threshold, outside range not inclusive and inside range not inclusive functionality based on the values placed in the CV1 and CV2 registers.

Parameters
instanceADC instance ID.
isEnabledThe switcher.
static void adc_hal_configure_hw_compare_in_range ( uint32_t  instance,
bool  isEnabled 
)
inlinestatic

This function configures the compare function to check if the conversion result of the input being monitored is either inside or outside the range formed by the compare value registers (CV1 and CV2). However, the actual compare range should be determined alone with the function of adc_hal_configure_hw_compare_greater() as well.

Parameters
instanceADC instance ID.
isEnabledThe switcher.
static void adc_hal_set_hw_compare_value1 ( uint32_t  instance,
uint32_t  value 
)
inlinestatic

This function sets the value of the CV1 register.

Parameters
instanceADC instance ID.
valueThe setting value.
static void adc_hal_set_hw_compare_value2 ( uint32_t  instance,
uint32_t  value 
)
inlinestatic

This function sets the value of the CV2 register.

Parameters
instanceADC instance ID.
valueThe setting value.
static void adc_hal_configure_dma ( uint32_t  instance,
bool  isEnabled 
)
inlinestatic

When DMA is enabled, it asserts the ADC DMA request during the ADC conversion complete event noted by the assertion of any of the ADC COCO flags.

Parameters
instanceADC instance ID.
isEnabledThe switcher.
static void adc_hal_disable ( uint32_t  instance,
uint32_t  group 
)
inlinestatic

Here the "NUll" channel is set to the conversion channel.

Parameters
instanceADC instance ID.
groupThe group mux index.
static void adc_hal_enable ( uint32_t  instance,
uint32_t  group,
adc_channel_mode_t  mode,
bool  isDifferential 
)
inlinestatic

When the available channel is set, the conversion begins to execute.

Parameters
instanceADC instance ID.
groupThe group mux index.
modeThe selection of channel number.
isDifferentialthe selection of differential input.
static void adc_hal_configure_interrupt ( uint32_t  instance,
uint32_t  group,
bool  isEnabled 
)
inlinestatic

This function enables conversion complete interrupts. When COCO is set while the respective AIEN is high, an interrupt is asserted.

Parameters
instanceADC instance ID.
groupThe group mux index.
inEnableThe switcher.
static bool adc_hal_is_in_process ( uint32_t  instance)
inlinestatic

This function indicates that a conversion or hardware averaging is in progress. ADACT is set when a conversion is initiated and cleared when a conversion is completed or aborted. Note that if the continuous conversion is been use, this function will always return true.

Parameters
instanceADC instance ID.
Returns
true if it is.
static bool adc_hal_is_conversion_completed ( uint32_t  instance,
uint32_t  group 
)
inlinestatic

This function indicates whether each conversion is completed.

Parameters
instanceADC instance ID.
groupThe grout mux index.
Returns
true if it is.
static bool adc_hal_is_calibration_fail ( uint32_t  instance)
inlinestatic

This function displays the result of the calibration sequence.

Parameters
instanceADC instance ID.
Returns
true if it is.
static uint32_t adc_hal_get_conversion_value ( uint32_t  instance,
uint32_t  group 
)
inlinestatic

This function returns the conversion value kept in the Rn Register. Unused bits in the Rn register are cleared in unsigned right justified modes and carry the sign bit (MSB) in sign extended 2's complement modes.

Parameters
instanceADC instance ID.
groupThe group mux index.
static void adc_hal_set_group_mux ( uint32_t  instance,
adc_group_mux_mode_t  group 
)
inlinestatic

ADC Mux select bit changes the ADC group setting to select between alternate sets of ADC channels. It will activate group A or group B.

Parameters
instanceADC instance ID.
groupThe group mux index.